package Year22_Month05.day24;

import java.util.Arrays;

public class 冒泡排序 {
    public static void bubbleSort(int[] arr){
        for (int i = arr.length; i > 0; i--) {
            for (int j = 0; j < i - 1; j++) {
                if(arr[j] > arr[j + 1]){
                    swap(arr,j,j+1);
                }
            }
        }
    }
    public static void swap(int[] arr,int i,int j){
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }

    public static void main(String[] args) {
        int[] arr = {4,2,8,6,9,1,3,5,0,7};
        bubbleSort(arr);
        System.out.println(Arrays.toString(arr));
    }
}
